<!DOCTYPE html>
<html lang="en">
<head>
    {template 'common/edithead'}
    <!--微擎 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
    <script type="text/javascript">
        //编辑器里使用
        var urobj=[];
    </script>
    <style>
        .container .type3,.container .type2,.type1{display: none;}
        .parameter>li{display:-webkit-flex; display:-webkit-box; display:-ms-flexbox; display:-moz-flex; display:flex;}
        .parameter>li input{-webkit-flex:1; -webkit-box-flex:1; -ms-flex:1; -moz-flex:1; flex:1;}
        .parameter>li .input-group-btn{width: auto;}
        .income li.income_top>input:nth-child(1),.income li.income_top>input:nth-child(2){width: 50%;}
        .income li.income_bottom>input:nth-child(2),.income li.income_bottom>input:nth-child(3),.income li.income_bottom>input:nth-child(4),.income li.income_bottom>input:nth-child(5),.income li.income_bottom>input:nth-child(6){width: 25%;}
        .type1,.type2.type3{display: none;}
    </style>
</head>
<body class="nav-md" style="min-width: 800px">
<div>
    <div class="container xc_edit_from" >
        <div class="main_container" style="overflow-x: hidden;min-height: calc(100vh - 20px);background-color: white;width: 100%;">
            <div class="col-md-12 col-xs-12">
                <div class="x_panel">
                    <ul class="we7-page-tab">
                        <li >
                            <a  href="{php echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}">
                                {$xtitleb}- {$xtitlea}列表  </a></li>
                        <li><a a href="{php echo $this->createWebUrl($do, array('op'=>'edit','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}">{$xtitleb}- {$xtitlea}增加</a></li>
                    </ul>
                    <div class="x_content">
                        <br/>
                        <form id="sign-form" class="form-horizontal" role="form" method="post" name="submit">
                            <input type="hidden" name="id" value="{$list['id']}">
                            <input type="hidden" name="format">
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">标题</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <input type="text" class="form-control" placeholder="标题" name="name" value="{$list[name]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">副标题</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <input type="text" class="form-control" placeholder="副标题" name="title" value="{$list[title]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="control-label col-md-2 col-sm-3 col-xs-12">类型</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <label class="radio inline">
                                        <input type="radio" class="ui-radio" name="type" id="type1" value="1" {if $list['type']==1}checked{/if}>无
                                    </label>
                                    <label class="radio inline">
                                        <input type="radio" class="ui-radio" name="type" id="type2" value="2" {if $list['type']==2}checked{/if}>团购
                                    </label>
                                    <label class="radio inline" style="width: 100px;">
                                        <input type="radio" class="ui-radio" name="type" id="type3" value="3" {if $list['type']==3}checked{/if}>限时抢购
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">分类</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <select  class="form-control js-select2" name="cid" data-select="{$list['cid']}">
                                        <option value="">请选择分类</option>
                                        {loop $class $index $item}
                                        <option value="{$item['id']}" {if $item['id']==$list['cid']}selected{/if} >{$item['name']}</option>
                                        {/loop}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">封面（340*288）</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    {php echo tpl_form_field_image('simg',$list[simg]);}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">产品图片</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    {php echo tpl_form_field_multi_image('bimg',$list[bimg]);}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">已售</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <input type="text" class="form-control" placeholder="已售" name="sold" value="{$list[sold]}">
                                    <span class="help-block">物品虚拟已售件数，用户下单此数据就增加, 无论是否支付</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">价格</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <input type="text" class="form-control" placeholder="价格" name="price" value="{$list[price]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">多规格</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <ul class="parameter" data-field="format">
                                        {if $list['format']}
                                        {loop $list['format'] $index $item}
                                        <li class="input-group">
                                            <input type="text" class="form-control" name="format_name"
                                                   value="{$item['name']}" placeholder="名称">
                                            <input type="text" class="form-control" name="format_price"
                                                   value="{$item['price']}" placeholder="价格">
                                            <input type="text" class="form-control type2" name="group_price"
                                                   value="{$item['group_price']}" placeholder="团购价格">
                                            <input type="text" class="form-control type3" name="limit_price"
                                                   value="{$item['limit_price']}" placeholder="抢购价格">
                                            <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                                                <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                                            </span>
                                            <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                                                <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                                            </span>
                                        </li>
                                        {/loop}
                                        {else}
                                        <li class="input-group">
                                            <input type="text" class="form-control" name="format_name"
                                                   value="" placeholder="名称">
                                            <input type="text" class="form-control" name="format_price"
                                                   value="" placeholder="价格">
                                            <input type="text" class="form-control type2" name="group_price"
                                                   value="" placeholder="团购价格">
                                            <input type="text" class="form-control type3" name="limit_price"
                                                   value="" placeholder="抢购价格">
                                            <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                                                <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                                            </span>
                                            <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                                                <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                                            </span>
                                        </li>
                                        {/if}
                                    </ul>
                                </div>
                            </div>
                            <script>
                                var parameter = {
                                    parameter_add: function (objc) {
                                        $(objc).parent().after('<li class="input-group"> <input type="text" class="form-control"  name="format_name" value="" placeholder="名称"><input type="text" class="form-control"  name="format_price" value="" placeholder="价格"><input type="text" class="form-control type3" name="limit_price"value="" placeholder="抢购价格"><input type="text" class="form-control type2" name="group_price"value="" placeholder="团购价格"><span class="input-group-btn" onclick="parameter.parameter_add(this)"> <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button> </span> <span class="input-group-btn" onclick="parameter.parameter_del(this)"> <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button> </span></li>');
                                        vip();
                                    },
                                    parameter_del: function (objc) {
                                        if ($(objc).parent().siblings().length > 0) {
                                            $(objc).parent().remove();
                                        }
                                    }
                                }
                            </script>
                            <div class="form-group type2">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">团购人数</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <input type="text" class="form-control" placeholder="团购人数" name="group_member" value="{$list[group_member]}">
                                </div>
                            </div>
                            <div class="form-group type2">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">团购失败时间</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <div class="input-group">
                                        <input type="text" class="form-control" placeholder="团购失败时间" name="group_fail" value="{$list[group_fail]}">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button">小时</button>
                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group type3">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">活动时间</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    {php echo tpl_form_field_daterange('times',$list['times'],true);}
                                </div>
                            </div>
                            {if $share['status']==1}
                            {if $share['type']>=1}
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">一级分销佣金</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <div class="input-group">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">消费金额的</button>
                                        </span>
                                        <input type="text" class="form-control" name="share_one" value="{$list['share_one']}" placeholder="佣金">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">%</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            {/if}
                            {if $share['type']>=2}
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">二级分销佣金</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <div class="input-group">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">消费金额的</button>
                                        </span>
                                        <input type="text" class="form-control" name="share_two" value="{$list['share_two']}" placeholder="佣金">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">%</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            {/if}
                            {if $share['type']>=3}
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">三级分销佣金</label>
                                <div class="col-md-10 col-sm-9 col-xs-12">
                                    <div class="input-group">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">消费金额的</button>
                                        </span>
                                        <input type="text" class="form-control" name="share_three" value="{$list['share_three']}" placeholder="佣金">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">%</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            {/if}
                            {/if}
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">首页显示</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="index"
                                           data-value="{$list['index']}" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">状态</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="status"
                                           data-value="{$list['status']}" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">排序</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="sort" value="{$list['sort']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-2 col-sm-3 col-xs-12">详情</label>
                                <div class="col-sm-10">
                                    {php echo tpl_ueditor('content',$list['content']);}
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="button" name="submit" class="btn btn-default" value="提交">
                                    <a type="button" class="btn btn-default"  href="{php echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=> urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}" >返回</a>
                                    <input id="res" name="res" type="reset" style="display:none;" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
{template 'common/editfoot'}
<script>
    function vip(){
        if($("#type1").is(":checked")){
            $(".type2").hide();
            $(".type3").hide();
            $(".type1").show();
        }else if($("#type2").is(":checked")){
            $(".type1").hide();
            $(".type3").hide();
            $(".type2").show();
        }else if($("#type3").is(":checked")){
            $(".type1").hide();
            $(".type2").hide();
            $(".type3").show();
        }
    }
    vip();
    $(function(){
        $("input[name='type']").change(function(){
            vip();
        });
        $("input[name='submit']").click(function(){
            getjson();
            var data=$(".form-horizontal").serialize();
            $.ajax({
                type:"post",
                url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'savemodel','version_id'=>$_GPC['version_id'])}",
                data:data,
                dataType:'json',
                success:function(res){
                    if(res.status==1){
                        if($("input[name='id']").val()==""){
                            $("input[name='res']").click();
                            $("body").find(".img-responsive.img-thumbnail").attr("src","");
                        }
                        swal('操作成功!', '操作成功!', 'success');
                    }else{
                        swal('操作失败!', '操作失败!', 'error');
                    }
                }
            })
        });
    })

    function getjson(){
        var format=[];
        $(".parameter").find("li").each(function(){
            var name=$(this).find("input[name='format_name']").val();
            var price=$(this).find("input[name='format_price']").val();
            var group_price=$(this).find("input[name='group_price']").val();
            var limit_price=$(this).find("input[name='limit_price']").val();
            if(name!=""){
                var data={name:name,price:price,limit_price:limit_price,group_price:group_price};
                format.push(data);
            }
        });
        if(format.length>0){
            $("input[name='format']").val(JSON.stringify(format));
        }
    }
</script>
</body>
</html>